/*     */ package com.feeyin.radar.sys.service.impl;
/*     */ 
/*     */ import com.feeyin.radar.commons.DateUtils;
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.crm.dao.ContractBackCostDAO;
/*     */ import com.feeyin.radar.crm.dao.ContractDAO;
/*     */ import com.feeyin.radar.crm.dao.ContractDetailDAO;
/*     */ import com.feeyin.radar.crm.dao.CustomerDAO;
/*     */ import com.feeyin.radar.crm.dao.SaleCostDAO;
/*     */ import com.feeyin.radar.sys.dao.BusinessTargetDAO;
/*     */ import com.feeyin.radar.sys.dao.ManageSetDAO;
/*     */ import com.feeyin.radar.sys.dao.UserDAO;
/*     */ import com.feeyin.radar.sys.form.SaleAssistantForm;
/*     */ import com.feeyin.radar.sys.model.ManageSet;
/*     */ import com.feeyin.radar.sys.service.SaleAssistantService;
/*     */ import java.math.BigDecimal;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ 
/*     */ public class SaleAssistantServiceImpl
/*     */   implements SaleAssistantService
/*     */ {
/*     */   private BusinessTargetDAO businessTargetDAO;
/*     */   private ManageSetDAO manageSetDAO;
/*     */   private ContractDAO contractDAO;
/*     */   private ContractDetailDAO contractDetailDAO;
/*     */   private ContractBackCostDAO contractBackCostDAO;
/*     */   private SaleCostDAO saleCostDAO;
/*     */   private CustomerDAO customerDAO;
/*     */   private UserDAO userDAO;
/*     */ 
/*     */   public BusinessTargetDAO getBusinessTargetDAO()
/*     */   {
/*  43 */     return this.businessTargetDAO;
/*     */   }
/*     */ 
/*     */   public void setBusinessTargetDAO(BusinessTargetDAO businessTargetDAO) {
/*  47 */     this.businessTargetDAO = businessTargetDAO;
/*     */   }
/*     */ 
/*     */   public ManageSetDAO getManageSetDAO() {
/*  51 */     return this.manageSetDAO;
/*     */   }
/*     */ 
/*     */   public void setManageSetDAO(ManageSetDAO manageSetDAO) {
/*  55 */     this.manageSetDAO = manageSetDAO;
/*     */   }
/*     */ 
/*     */   public ContractDAO getContractDAO() {
/*  59 */     return this.contractDAO;
/*     */   }
/*     */ 
/*     */   public void setContractDAO(ContractDAO contractDAO) {
/*  63 */     this.contractDAO = contractDAO;
/*     */   }
/*     */ 
/*     */   public ContractBackCostDAO getContractBackCostDAO() {
/*  67 */     return this.contractBackCostDAO;
/*     */   }
/*     */ 
/*     */   public void setContractBackCostDAO(ContractBackCostDAO contractBackCostDAO) {
/*  71 */     this.contractBackCostDAO = contractBackCostDAO;
/*     */   }
/*     */ 
/*     */   public ContractDetailDAO getContractDetailDAO() {
/*  75 */     return this.contractDetailDAO;
/*     */   }
/*     */ 
/*     */   public void setContractDetailDAO(ContractDetailDAO contractDetailDAO) {
/*  79 */     this.contractDetailDAO = contractDetailDAO;
/*     */   }
/*     */ 
/*     */   public SaleCostDAO getSaleCostDAO() {
/*  83 */     return this.saleCostDAO;
/*     */   }
/*     */ 
/*     */   public void setSaleCostDAO(SaleCostDAO saleCostDAO) {
/*  87 */     this.saleCostDAO = saleCostDAO;
/*     */   }
/*     */ 
/*     */   public CustomerDAO getCustomerDAO() {
/*  91 */     return this.customerDAO;
/*     */   }
/*     */ 
/*     */   public void setCustomerDAO(CustomerDAO customerDAO) {
/*  95 */     this.customerDAO = customerDAO;
/*     */   }
/*     */ 
/*     */   public UserDAO getUserDAO() {
/*  99 */     return this.userDAO;
/*     */   }
/*     */ 
/*     */   public void setUserDAO(UserDAO userDAO) {
/* 103 */     this.userDAO = userDAO;
/*     */   }
/*     */ 
/*     */   public SaleAssistantForm getBusinessTarget(Integer currentUserId) {
/* 107 */     SaleAssistantForm businessTarget = new SaleAssistantForm();
/* 108 */     if (currentUserId == null) return businessTarget;
/*     */ 
/* 111 */     BigDecimal periodTarget = new BigDecimal(0);
/* 112 */     BigDecimal[] periodFinishedTarget = new BigDecimal[2];
/* 113 */     periodFinishedTarget[0] = new BigDecimal(0);
/* 114 */     periodFinishedTarget[1] = new BigDecimal(0);
/*     */ 
/* 116 */     List list = new ArrayList();
/* 117 */     ManageSet manageSet = new ManageSet();
/* 118 */     list = this.manageSetDAO.getManageSetByType("2");
/* 119 */     if ((list != null) && (list.size() > 0)) {
/* 120 */       manageSet = (ManageSet)list.get(0);
/* 121 */       if (manageSet != null) {
/* 122 */         businessTarget.setAssignPeriod(manageSet.getStatus());
/* 123 */         if ("3".equals(manageSet.getStatus()))
/* 124 */           periodTarget = this.businessTargetDAO.getYearTargetBySalePersonId(currentUserId);
/*     */         else {
/* 126 */           periodTarget = this.businessTargetDAO.getTargetByAssignPeriod(currentUserId, manageSet.getStatus());
/*     */         }
/* 128 */         businessTarget.setPeriodTarget(periodTarget);
/*     */       }
/*     */     }
/*     */ 
/* 132 */     periodFinishedTarget = this.businessTargetDAO.getFinishedTarget(currentUserId, manageSet.getStatus());
/* 133 */     businessTarget.setFinishedTarget(periodFinishedTarget[0]);
/* 134 */     businessTarget.setContractCost(periodFinishedTarget[1]);
/*     */ 
/* 136 */     if ((periodTarget != null) && (periodTarget.compareTo(new BigDecimal(0)) > 0) && 
/* 137 */       (periodFinishedTarget[0] != null) && (periodFinishedTarget[0].compareTo(new BigDecimal(0)) > 0)) {
/* 138 */       BigDecimal temp = new BigDecimal(0);
/* 139 */       temp = periodFinishedTarget[0].divide(periodTarget, 12, 4);
/* 140 */       if ((temp != null) && (temp.compareTo(new BigDecimal(0)) > 0)) {
/* 141 */         businessTarget.setFinishedRate(temp.multiply(new BigDecimal(100)));
/*     */       }
/*     */     }
/*     */ 
/* 145 */     businessTarget.setSaleCost(this.saleCostDAO.getPeriodSaleCost(currentUserId, manageSet.getStatus()));
/* 146 */     if ((periodTarget != null) && (periodTarget.compareTo(new BigDecimal(0)) > 0)) {
/* 147 */       BigDecimal targetSign = new BigDecimal(0);
/* 148 */       targetSign = periodTarget.divide(new BigDecimal(3), 0, 4);
/* 149 */       businessTarget.setTargetSign1(targetSign);
/* 150 */       businessTarget.setTargetSign2(targetSign.add(targetSign));
/* 151 */       businessTarget.setTargetSign3(targetSign.add(targetSign).add(targetSign));
/*     */     }
/*     */ 
/* 154 */     BigDecimal predictCost = new BigDecimal(0);
/* 155 */     predictCost = this.customerDAO.getPeriodPredictCost(currentUserId, manageSet.getStatus());
/* 156 */     if (predictCost == null) {
/* 157 */       predictCost = new BigDecimal(0);
/*     */     }
/* 159 */     businessTarget.setPredictCost(predictCost);
/*     */ 
/* 163 */     ManageSet ms = new ManageSet();
/* 164 */     ms.setMType("11");
/* 165 */     ms.setStatus("1");
/* 166 */     ms = this.manageSetDAO.getManageSetByTypeStatus(ms);
/* 167 */     if (ms != null) {
/* 168 */       businessTarget.setType(ms.getCode());
/*     */ 
/* 170 */       businessTarget.getSaleTop5s().addAll(getTopContractOrBackCostOrGrossProfit(manageSet.getStatus()));
/*     */     }
/* 172 */     return businessTarget;
/*     */   }
/*     */ 
/*     */   private List getTopContractOrBackCostOrGrossProfit(String assignPeriod)
/*     */   {
/* 180 */     if (StringUtils.isEmpty(assignPeriod)) return null;
/* 181 */     Date startDate = DateUtils.getCurrentYearFirstDay();
/* 182 */     Date endDate = DateUtils.getCurrentYearEndDay();
/*     */ 
/* 184 */     if ("1".equals(assignPeriod)) {
/* 185 */       startDate = DateUtils.getCurrentMonthFirstDay();
/* 186 */       endDate = DateUtils.getCurrentMonthEndDay();
/* 187 */     } else if ("2".equals(assignPeriod)) {
/* 188 */       startDate = DateUtils.getCurrentSeasonFirstDay();
/* 189 */       endDate = DateUtils.getCurrentSeasonEndDay();
/* 190 */     } else if ("3".equals(assignPeriod)) {
/* 191 */       startDate = DateUtils.getCurrentYearFirstDay();
/* 192 */       endDate = DateUtils.getCurrentYearEndDay();
/*     */     }
/*     */ 
/* 195 */     ManageSet manageSet = new ManageSet();
/* 196 */     manageSet.setMType("11");
/* 197 */     manageSet.setStatus("1");
/* 198 */     manageSet = this.manageSetDAO.getManageSetByTypeStatus(manageSet);
/* 199 */     if (manageSet == null) return null;
/*     */ 
/* 201 */     String code = manageSet.getCode();
/* 202 */     String value = manageSet.getMValue();
/* 203 */     List users = new ArrayList();
/* 204 */     if ("isContract".equals(code))
/* 205 */       users = this.userDAO.getTopFinishedContractCost(startDate, endDate);
/* 206 */     else if ("isBackCost".equals(code))
/* 207 */       users = this.userDAO.getTopFinishedBackCost(startDate, endDate);
/* 208 */     else if ("isGrossProfit".equals(code))
/* 209 */       users = this.userDAO.getTopFinishedGrossProfit(startDate, endDate);
/* 210 */     else if ("isHand".equals(code))
/* 211 */       users = this.userDAO.getTopFinishedHandGrossProfit(startDate, endDate);
/* 212 */     else if ("isGrossBackCost".equals(code)) {
/* 213 */       users = this.userDAO.getTopFinishedGrossBackCost(startDate, endDate);
/*     */     }
/* 215 */     return users;
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.service.impl.SaleAssistantServiceImpl
 * JD-Core Version:    0.6.0
 */